﻿/*
=============================================================================
Author:魏宝辉通过CodeSmithe生成
CreatedTime:2012-10-16
Description:Sms_Log.aspx.cs页面代码
=============================================================================	
*/

using System;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

public partial class Sms_Log : System.Web.UI.Page 
{

    string TableName = "Sms_Log";//表名
    static string SqlWhere = " 1=1 ";//过滤条件
    string GetCountSql = "select count(id)  from Sms_Log where " + SqlWhere ;
    string SqlTable = "select *  from Sms_Log where " + SqlWhere + "  order by id desc ";
    string ReturnPage = "Sms_Log.aspx";
    string SearchFilter = " and ( id like '%{0}%'  )";//默认搜索id，其他字段按需添加

    FTchina.SearchQuery.QueryModel qm = new FTchina.SearchQuery.QueryModel();//实例化模型

    protected void Page_Load(object sender, EventArgs e)
    {
        FTchina.basic.CheckAdmin(this);        
        FTchina.basic.ChkPoewr(this, FTchina.Api.htmlpath.GetCurrentPagePath());
 		if (!IsPostBack)
        {	
			string act = FTchina.basic.FilterSQL(Request["act"]);
			switch (act)
            {
                case "mod":
                    {
                         btnSms_LogOk.Text = "确定修改";
                        txbid.Enabled = false;
                        DisplayData();
                        plop.Visible = true;
                        break;
                    }
                case "del":
                    {
                        DeleteData();
                        break;
                    }
                case "add":
                    {
                        txbid.Text = "0";
                        txbid.Visible = false;
                        plop.Visible = true;//添加修改的表单可以看见
                        break;
                    }
                default:
                    {
                        txbid.Text = "0";
                        txbid.Visible = false;
                        plop.Visible = false;//添加修改的表单看不见
                        break;
                    }

            }
            
             if (qm.WorkPage != ReturnPage)
            {
                qm.TableName = TableName;
                qm.GetCountSql = GetCountSql;
                qm.GetTableSql = SqlTable;
                qm.ReturnPage = ReturnPage;
                qm.SqlWhere = SqlWhere;
                qm.WorkPage = ReturnPage;
                qm.Key1 = string.Empty;

            }
             
            bindData(qm);
		}
    }
	
	private void DeleteData()
    {
		 FTchina.UImsg.PageRender(FTchina.BLL.Sms_LogManager.DeleteSms_LogByid(Convert.ToInt32(FTchina.basic.FilterSQL(Request["id"])))>0, HttpContext.Current.Request.Path.ToString());
	}
	private void DisplayData()
    {
         FTchina.Models.Sms_Log mSms_Log = FTchina.BLL.Sms_LogManager.GetSms_LogByid(Convert.ToInt32(FTchina.basic.FilterSQL(Request["id"])));
if (mSms_Log != null)
        {
			 txbid.Text=mSms_Log.Id.ToString();
					
			 txbsendtime.Text=mSms_Log.Sendtime.ToString();
					
			 txbsenderID.Text=mSms_Log.SenderID.ToString();
					
			 txbtarget.Text=mSms_Log.Target.ToString();
					
			 txbscontent.Text=mSms_Log.Scontent.ToString();
					
			 txbstate.Text=mSms_Log.State.ToString();
					
			 txbstatetime.Text=mSms_Log.Statetime.ToString();
					
			 txbsmsguid.Text=mSms_Log.Smsguid.ToString();
					
			 txbtaskstate.Text=mSms_Log.Taskstate.ToString();
					
			 txbshenhe.Text=mSms_Log.Shenhe.ToString();
					
			 txbsendcount.Text=mSms_Log.Sendcount.ToString();
					
			 txblockguid.Text=mSms_Log.Lockguid.ToString();
					
}
        else
        {
            FTchina.UImsg.PageError("无数据！", HttpContext.Current.Request.Path.ToString());
        }
    }

    private void DataModifiy()
    {
        FTchina.Models.Sms_Log mSms_Log = new FTchina.Models.Sms_Log();
        
			mSms_Log.Id  =Convert.ToInt32(FTchina.basic.FilterSQL(txbid.Text));
					
			mSms_Log.Sendtime  =Convert.ToDateTime(FTchina.basic.FilterSQL(txbsendtime.Text));
					
			mSms_Log.SenderID  =FTchina.basic.FilterSQL(txbsenderID.Text);
					
			mSms_Log.Target  =FTchina.basic.FilterSQL(txbtarget.Text);
					
			mSms_Log.Scontent  =FTchina.basic.FilterSQL(txbscontent.Text);
					
			mSms_Log.State  =FTchina.basic.FilterSQL(txbstate.Text);
					
			mSms_Log.Statetime  =Convert.ToDateTime(FTchina.basic.FilterSQL(txbstatetime.Text));
					
			mSms_Log.Smsguid  =FTchina.basic.FilterSQL(txbsmsguid.Text);
					
			mSms_Log.Taskstate  =FTchina.basic.FilterSQL(txbtaskstate.Text);
					
			mSms_Log.Shenhe  =FTchina.basic.FilterSQL(txbshenhe.Text);
					
			mSms_Log.Sendcount  =Convert.ToInt32(FTchina.basic.FilterSQL(txbsendcount.Text));
					
			mSms_Log.Lockguid  =FTchina.basic.FilterSQL(txblockguid.Text);
					
		
		FTchina.UImsg.PageRender(FTchina.BLL.Sms_LogManager.ModifySms_LogByid(mSms_Log)>0);
        
    }
    private void DataAdd()
    {
        FTchina.Models.Sms_Log mSms_Log = new FTchina.Models.Sms_Log();
        
			mSms_Log.Id = Convert.ToInt32(FTchina.basic.FilterSQL(txbid.Text));
					
			mSms_Log.Sendtime = Convert.ToDateTime(FTchina.basic.FilterSQL(txbsendtime.Text));
					
			mSms_Log.SenderID = FTchina.basic.FilterSQL(txbsenderID.Text);
					
			mSms_Log.Target = FTchina.basic.FilterSQL(txbtarget.Text);
					
			mSms_Log.Scontent = FTchina.basic.FilterSQL(txbscontent.Text);
					
			mSms_Log.State = FTchina.basic.FilterSQL(txbstate.Text);
					
			mSms_Log.Statetime = Convert.ToDateTime(FTchina.basic.FilterSQL(txbstatetime.Text));
					
			mSms_Log.Smsguid = FTchina.basic.FilterSQL(txbsmsguid.Text);
					
			mSms_Log.Taskstate = FTchina.basic.FilterSQL(txbtaskstate.Text);
					
			mSms_Log.Shenhe = FTchina.basic.FilterSQL(txbshenhe.Text);
					
			mSms_Log.Sendcount = Convert.ToInt32(FTchina.basic.FilterSQL(txbsendcount.Text));
					
			mSms_Log.Lockguid = FTchina.basic.FilterSQL(txblockguid.Text);
					
		
		FTchina.UImsg.PageRender(FTchina.BLL.Sms_LogManager.AddSms_Log(mSms_Log)>0);
    }
    
	
    protected void btnSms_LogOk_Click(object sender, EventArgs e)
    {
 		if (btnSms_LogOk.Text == "确定修改") DataModifiy();
        else DataAdd();
    }
    
    
    #region gvList显示

    private void bindData(FTchina.SearchQuery.QueryModel qm)
    {
       
        int pCurrentPage = (FTchina.basic.SafeRequest(Request["page"]).Length > 0) ? Convert.ToInt32(FTchina.basic.SafeRequest(Request["page"])) : 1;
        int pageSize = 15;//每页的数据
        int AllCount = Convert.ToInt32(FTchina.shujuku.GetDataTable(qm.GetCountSql).Rows[0][0].ToString());//数据总条目数
        litpager.Text = FTchina.Api.Pager.GetPagerWithPageName(qm.GetTableSql, AllCount, pCurrentPage, pageSize, qm.ReturnPage);
        gvList.DataSource = FTchina.shujuku.ShowForPage(qm.TableName,qm.SqlWhere, pCurrentPage, pageSize);
        gvList.DataBind();
        txbsearch.Text = qm.Key1;//搜索条件赋值
       
    }
     /// <summary>
    /// 为了实现<thead> <TH>and <tbody>，满足点击表头排序功能
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
   public void gvList_PreRender(object sender, EventArgs e)
    {
        if (gvList.Rows.Count > 0)
        { 
            // 使用<TH>替换<TD> 
            gvList.UseAccessibleHeader = true;
            //This will add the <thead> and <tbody> elements 
            //HeaderRow将被<thead>包裹，数据行将被<tbody>包裹 
            gvList.HeaderRow.TableSection = TableRowSection.TableHeader;
            // FooterRow将被<tfoot>包裹 
            gvList.FooterRow.TableSection = TableRowSection.TableFooter;
        }
    }
    #endregion


    
      

    #region GridView等控件导出到Excel
    protected void btnexcel_Click(object sender, EventArgs e)
    {
        //将分页去除
        gvList.Width = Unit.Percentage(100);
        gvList.AutoGenerateColumns = false;
        gvList.AllowPaging = false;
        string GetDateSql = string.Format(SqlTable, TableName);
        DataSet ds = FTchina.shujuku.GetDataSet(GetDateSql);
        gvList.DataSource = ds;
        gvList.DataBind();

        System.IO.StringWriter stringWrite = new System.IO.StringWriter();
        System.Web.UI.HtmlTextWriter writer = new System.Web.UI.HtmlTextWriter(stringWrite);
        gvList.RenderControl(writer);

        FTchina.Api.ToExcel.HtmlTableToExcel(stringWrite.ToString());
    }
    public override void VerifyRenderingInServerForm(Control control)
    {
        // 覆盖VerifyRenderingInServerForm方法，非常重要，否则系统会报错
        //base.VerifyRenderingInServerForm(control);
    }
    #endregion
    #region 搜索按钮
    protected void btnsearch_Click(object sender, EventArgs e)
    {
       
        string SqlWhere = " 1=1  ";//过滤条件，清空其他的过滤条件
        if (txbsearch.Text.Trim().Length > 0)
        {
            qm.Key1 = txbsearch.Text.Trim();
            SqlWhere += string.Format(SearchFilter, qm.Key1);
        }
 	else
        {
            qm.Key1 = "";
        }
        string GetCountSql = "select count(id)  from Sms_Log where " + SqlWhere ;
        string SqlTable = "select *  from Sms_Log where " + SqlWhere + "  order by id desc ";
        //FTchina.basic.Log(GetCountSql);
        qm.TableName = TableName;
        qm.GetCountSql = GetCountSql;
        qm.GetTableSql = SqlTable;
        qm.ReturnPage = ReturnPage;
        qm.SqlWhere = SqlWhere;
        qm.WorkPage = ReturnPage;
        bindData(qm);
    }
    #endregion

    
}




 

